package com.itheima.workdemo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ajaxJsonTest01Servlet")
public class AjaxJsonTest01Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         //需求请求和响应都是普通字符串
        //TOODO注意这里不需要在解决请求或者响应乱码的问题因为前面已经配置了过滤器会对这个
        //项目中每个向服务器或者向浏览器发送响应或者接收请求做了编码解码
        // 获取浏览器请求的数据
        String username = request.getParameter("name");
        String password = request.getParameter("password");//这里的名字必须要和前端给的参数名字一致
        //打印请求的数据
        System.out.println(username+"----"+password);

        //响应给浏览器数据
        response.getWriter().print("你好呀我是后端!");
    }
}